home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / www / cgi-bin / sendrm-cgi < prev    next >
Encoding:
Text File  |  1996-11-11  |  1.4 KB  |  45 lines

  1. #!/usr/bin/perl
  2.  
  3.  
  4. # QUERY_STRING stores the name of the absolute path to the compressed
  5. # tar file to transmit and then remove
  6. $abstmpdirpathNfile = $ENV{'QUERY_STRING'} ;
  7. $abstmpdirpathNfile =~ /(.*)\/[^\/]*$/;
  8. $abstmpdirpath = $1;
  9.  
  10. if (! -f $abstmpdirpathNfile) {
  11.    $str1 = "Content-type: text/html\n\n";
  12.    syswrite(STDOUT,$str1,length($str1));
  13.    $str2 = "File not found: $abstmpdirpathNfile<P>\n";
  14.    syswrite(STDOUT,$str2,length($str2));
  15.    exit 0;
  16. }
  17.  
  18. $str1 = "Content-type: application/octet-stream \n\n";
  19. syswrite(STDOUT,$str1,length($str1));
  20. open (INFILE, "<$abstmpdirpathNfile");
  21. while ($len = sysread(INFILE, $buf, 16384)) {
  22.     if (!defined $len) {
  23.         next if $! =~ /^Interrupted/;
  24.         die "System read error:  $!\n";
  25.     }
  26.     $offset = 0;
  27.     while ($len) {     # handle partial writes
  28.                        # in case syswrite doesn't write all of the buffer
  29.         $written = syswrite(STDOUT, $buf, $len, $offset);
  30.         die "System write error:  $!\n" unless defined $written;
  31.         $len -= $written;
  32.         $offset += $written;
  33.     }
  34. }
  35. close (INFILE);
  36. unlink ($abstmpdirpathNfile);
  37. if (! rmdir ($abstmpdirpath)) {
  38.     $val = "rmdir failed:$!";
  39.     open (INFILE, "> /usr/tmp/DTsee$$");
  40.     syswrite(INFILE,$val,length($val));
  41.     $val = "\n\n and, abstmpdirpath == $abstmpdirpath\n" ;
  42.     syswrite(INFILE,$val,length($val));
  43.     close (INFILE);
  44.     };
  45.